<template>
  <div class="app-container">
    <div class="contentBox">
      <div class="searchBox">
        <el-form :model="queryParams" ref="queryRef" :inline="true" @submit.prevent>
          <el-form-item prop="locationId" style="margin: 0 6px 0 0;">
            <SelectOption class="selectOptionBox" ref="locationSelectOption" placeHolder="请选择区域" title="区域选择" maxSelectLength="more"
                v-model="queryParams.locationId" @loadOptions="locationDataLoad" @chooseConfirm="handleQuery()" @clearChoose="handleQuery()" @chooseError="handleQueryError"/>
          </el-form-item>
          <el-select v-model="queryFormName" style="width: 120px" @change="changeQuerySet">
            <el-option
                v-for="item in queryOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
          </el-select>
          <el-form-item :prop="queryFormName" style="margin: 0 6px 0 0;">
            <el-input
                style="width: 200px;"
                v-model="queryParams[queryFormName]"
                placeholder="请输入"
                clearable
                @keyup.enter="handleQuery()"
            />
          </el-form-item>
          <el-form-item style="margin: 0 6px 0 0;">
            <el-button class="normalFormBg searchBtn" icon="Search" @click="handleQuery()"></el-button>
            <el-button class="normalFormBg searchBtn" icon="Refresh" @click="resetQuery()"></el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-row :gutter="10" style="margin: 16px 0;"></el-row>
      <el-table
          v-loading="loading"
          :data="dataList"
          border>
        <el-table-column prop="date" label="区域名称" width="100" :show-overflow-tooltip="true" fixed="left"></el-table-column>
        <el-table-column prop="creditCode" label="用户编号" width="150"></el-table-column>
        <el-table-column prop="creditCode" label="用户名称" width="150"></el-table-column>
        <el-table-column prop="creditCode" label="门牌号" width="150"></el-table-column>
        <el-table-column prop="creditCode" label="手机号码" width="150"></el-table-column>
        <el-table-column prop="creditCode" label="通信地址" width="150"></el-table-column>
        <el-table-column prop="creditCode" label="表类型" width="150"></el-table-column>
        <el-table-column prop="creditCode" label="表地址" width="150"></el-table-column>
        <el-table-column prop="creditCode" label="缴费类型" width="150"></el-table-column>
        <el-table-column label="操作" align="center" width="340" class-name="small-padding fixed-width" fixed="right">
          <template #default="scope">
            <div class="pageFlex pageFlexCenter" style="width: 100%;">
              <div class="pageFlex pageFlexCenter btnSetBox" @click="handleCancel(scope.row.id)">
                <img src="@/assets/images/delete.png" class="img">
                <div class="text">销表</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <template #empty>
          <el-empty description="暂无数据" style="color: var(--el-color-primary);"/>
        </template>
      </el-table>
      <div class="pageFlex pageAlignCenter pageSpaceBetween" style="margin-top: 20px;">
        <div class="totalText">共计 {{total}} 条</div>
        <el-pagination background layout="prev, pager, next" :total="total" :current-page="queryParams.pageNum" :page-size="queryParams.pageSize" @current-change="handleCurrentChange"/>
      </div>
    </div>
    <el-drawer v-model="modalShow" direction="rtl" size="600" :title="modalTitle">
      <div class="modalBox">
        <div class="modalBoxContent">
          <el-form
              ref="formRef"
              class="formContent"
              label-width="120"
              :model="form"
              :rules="rules"
          >
            <div class="formContentTop pageFlex pageAlignCenter">
              <div class="line"></div>
              <div class="title">销户信息</div>
            </div>
            <div class="formContentCenter bgFF">
              <el-form-item label="用户编号" prop="name">
                <el-input
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入用户编号"
                    clearable
                />
              </el-form-item>
              <el-form-item label="用户名称" prop="name">
                <el-input
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入用户名称"
                    clearable
                />
              </el-form-item>
              <el-form-item label="卡号" prop="name">
                <el-input
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入卡号"
                    clearable
                />
              </el-form-item>
              <el-form-item label="卡区号" prop="name">
                <el-input
                    type="number"
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入卡区号"
                    clearable
                />
              </el-form-item>
              <el-form-item label="总购买金额" prop="name">
                <el-input
                    type="number"
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入总购买金额"
                    clearable
                />
              </el-form-item>
              <el-form-item label="用户余额" prop="name">
                <el-input
                    type="number"
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入用户余额"
                    clearable
                />
              </el-form-item>
            </div>
            <div class="formContentTop pageFlex pageAlignCenter">
              <div class="line"></div>
              <div class="title">用户输入</div>
            </div>
            <div class="formContentCenter bgFF">
              <el-form-item label="剩余金额" prop="name">
                <el-input
                    type="number"
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入剩余金额"
                    clearable
                />
              </el-form-item>
              <el-form-item label="最后读数" prop="name">
                <el-input
                    type="number"
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入最后读数"
                    clearable
                />
              </el-form-item>
              <el-form-item label="应退金额" prop="name">
                <el-input
                    type="number"
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请输入应退金额"
                    clearable
                />
              </el-form-item>
              <el-form-item label="支付方式" prop="name">
                <el-input
                    type="number"
                    class="inputBox"
                    v-model="form.name"
                    placeholder="请选择支付方式"
                    clearable
                />
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="lineBox"></div>
        <div class="bottomBox pageFlex pageFlexCenter">
          <el-button type="primary" :loading="submitLoading" @click="submitNow">销户</el-button>
        </div>
        <el-button type="primary" :loading="formLoading" class="modalLoadingBox" v-if="formLoading">加载数据中</el-button>
      </div>
    </el-drawer>
  </div>
</template>
<script setup>
import { onMounted } from 'vue';
import SelectOption from '@/views/gasManage/components/SelectOption';
import { areasList } from '@/api/system/location';
const { proxy } = getCurrentInstance();
// ------------------------------------筛选条件------------------------------------
const queryFormName = ref('name');
const preFormName = ref('name');
const queryOptions = ref([
  {
    value: 'userNo',
    label: '用户编号',
  },
  {
    value: 'name',
    label: '用户名称',
  },
  {
    value: 'doorNum',
    label: '门牌号',
  },
  {
    value: 'phone',
    label: '手机号码',
  },
  {
    value: 'address',
    label: '通信地址',
  },
  {
    value: 'meterAddress',
    label: '表地址',
  }
])
function changeQuerySet(e){
  if(queryFormName.value !== preFormName.value){
    delete queryParams.value[preFormName.value];
    preFormName.value = e;
  }
}
async function locationDataLoad(e){
  const { node, resolve } = e;
  let id = node.level === 0 ? 0 : node.data.id;
  let data = [];
  if(node.data.isEnable != 0){
    data = await areasListApi({parentId: id});
    if(data.length){
      data.map(item=>{
        item.checked = item.isEnable == 0;
        return item
      })
    }
  }
  proxy.$refs.locationSelectOption.handleLoadApi(data, node, resolve);
}
function areasListApi(params){
  return new Promise(resolve => {
    areasList(params).then(res => {
      resolve(res.data);
    }).catch(() => {resolve(false)})
  })
}
// ------------------------------------查询---------------------------------------
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  locationId: '',
})
const loading = ref(false);
const total = ref(0);
const dataList = ref([]);
function handleQuery(){
  queryParams.value.pageNum = 1;
  getList();
}
function resetQuery(){
  proxy.resetForm("queryRef");
  queryParams.value.locationId = '';
  proxy.$refs.locationSelectOption.setDefaultData();
  handleQuery();
}
function handleQueryError(e){
  proxy.$modal.msgError(e.msg)
}
function getList(){
  loading.value = true;
  setTimeout(()=>{
    dataList.value = [
      {
        id: 1
      }
    ]
    loading.value = false;
  }, 1000)
}
function handleCurrentChange(e){
  queryParams.value.pageNum = e;
  getList();
}
// ------------------------------------弹窗---------------------------------------
const modalShow = ref(false);
const modalTitle = ref('');
const formLoading = ref(false);
const submitLoading = ref(false);
const form = ref({

})
const rules = ref({})
function submitNow(){
  console.log(form.value)
  // if(submitLoading.value) return;
  // proxy.$refs["formRef"].validate(valid => {
  //   if(valid){
  //     submitLoading.value = true;
  //
  //   }else{
  //     proxy.$modal.alertWarning('信息填写有误，请查看！');
  //   }
  // })
}
function handleModalShow(name){
  modalTitle.value = name;
  modalShow.value = true;
}
function handleModalHide(){
  modalShow.value = false;
}
// ------------------------------------换表---------------------------------------
function handleCancel(row){
  console.log(row)
  formLoading.value = true;
  setTimeout(()=>{
    formLoading.value = false;
  }, 1000)
  handleModalShow('远程销户');
}
onMounted(()=>{
  getList();
})
</script>
<style lang='scss' scoped>
@import "@/assets/styles/public.scss";
.app-container{
  width: 100%;
  min-height: calc(100vh - 66px);
  background: #F8F8F9;
}
.contentBox{
  width: 100%;
  background-color: #FFFFFF;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 12px;
  .searchBox{
    :deep(.el-input){
      .el-input__wrapper{
        background-color: $formBgSet;
        box-shadow: none;
        border-radius: 0 var(--el-border-radius-base) var(--el-border-radius-base) 0;
      }
    }
    :deep(.el-select){
      .el-select__wrapper{
        background-color: $formBgSet;
        box-shadow: none;
        border-radius: var(--el-border-radius-base) 0 0 var(--el-border-radius-base);
      }
    }
    .selectOptionBox{
      width: 200px;
      &:deep(.valueBox){
        border-radius: var(--el-border-radius-base);
      }
    }
    .searchBtn{
      width: 32px;
      height: 32px;
      font-size: 12px;
      padding: 0;
      border: none;
      margin: 0 6px 0 0px;
    }
  }
  .btnSetBox{
    padding: 0 10px;
    box-sizing: border-box;
    border-right: 1px solid $borderColor;
    cursor: pointer;
    .text{
      height: 16px;
      line-height: 16px;
      color: var(--el-color-primary);
    }
    .img{
      width: 16px;
      height: 16px;
      margin-right: 2px;
    }
    &:last-child{
      border-right: none;
    }
  }
  .totalText{
    height: 22px;
    font-weight: 400;
    font-size: 14px;
    color: #1D2129;
    line-height: 22px;
  }
}
:deep(.el-drawer){
  .el-drawer__header{
    margin: 0;
    padding-bottom: 20px;
  }
  .el-drawer__body{
    padding: 0;
  }
}
</style>

